<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function foo() {
            return new Promise(function (resolve, reject) {
                setTimeout(function () {
                    //resolve(123);
                    reject('error')
                }, 100);
            })
        };
        foo()
            .then(function (data) {
                console.log(data);
            })
            .catch(function (data) {
                console.log(data);
            })
            .finally(function () {
                console.log('finish');
            });

        //等效
        foo()
            .then(function (data) {
                console.log(data);
            }, function (data) {
                console.log(data);
            })

            .finally(function () {
                console.log('finish');
            });
    </script>
</body>

</html>